package com.victor.zjbj_android.yinhuan;

import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;

import com.victor.zjbj_android.R;
import com.victor.zjbj_android.base.BaseActivity;
import com.victor.zjbj_android.yinhuan.fragment.AdressFragment;
import com.victor.zjbj_android.yinhuan.fragment.XianChangqingkuangFragment;
import com.victor.zjbj_android.yinhuan.fragment.Xianshizhenggai2Fragment;
import com.victor.zjbj_android.yinhuan.fragment.XianshizhenggaiFragment;
import com.victor.zjbj_android.yinhuan.fragment.YanqiliyouFragment;
import com.victor.zjbj_android.yinhuan.fragment.YinhuanchuliFragment;

import java.util.ArrayList;
import java.util.List;

public class YinHuanInfoActivity extends BaseActivity {
    private String m_yh_sn;


    private TabLayout mTablayout;
    private ViewPager mViewPager;
    private List<Fragment> fragments;

    private YanqiliyouFragment myFragment1;
    private Xianshizhenggai2Fragment myFragment2;
    private XianChangqingkuangFragment myFragment3;




    @Override
    protected int getResourcesId() {
        return R.layout.activity_yin_huan_info;
    }

    @Override
    protected void init(Bundle savedInstanceState) {
        m_yh_sn = getIntent().getStringExtra("yh_sn");

        findViewById(R.id.iv_back).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        initFragments();
        initViews();
    }


    /*
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_yin_huan_info);
        findViewById(R.id.iv_back).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        initFragments();
        initViews();
    }
    */

    private void initFragments() {
        myFragment1 = YanqiliyouFragment.newInstance(0);
        myFragment2 = Xianshizhenggai2Fragment.newInstance(1);
        myFragment3 = XianChangqingkuangFragment.newInstance(2);
        fragments = new ArrayList<>();
        fragments.add(myFragment1);
        fragments.add(myFragment2);
        fragments.add(myFragment3);
    }

    private void initViews() {
        mViewPager=findViewById(R.id.viewPager);
        mTablayout=findViewById(R.id.tb_wenjian);
        MyYinHuanPagerAdapter myWenjianPagerAdapter=new MyYinHuanPagerAdapter(getSupportFragmentManager(),fragments,new String[]{"延期理由","限时整改","现场情况"});
        mViewPager.setAdapter(myWenjianPagerAdapter);
        mTablayout.setupWithViewPager(mViewPager);
        mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                switch (position){
                    case 0:
//                        myFragment1.refresh(0);
                        break;
                    case 1:
//                        myFragment2.refresh(1);
                        break;
                }
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }
}
